package my.edu.model.User.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import my.edu.common.domain.PageDTO;
import my.edu.common.domain.PageVO;
import my.edu.model.User.entity.SystemConfig;
import my.edu.model.User.entity.VO.OperationLogVO;
import my.edu.model.User.entity.dto.LogSearchDTO;
import my.edu.model.User.service.ISystemConfigService;
import my.edu.common.domain.Response;
import my.edu.model.information.entity.OperationLog;
import my.edu.model.information.service.IOperationLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/sys")
@Tag(name = "系统字段接口")
@Validated//接口单一参数校验必须添加此注解
public class SystemConfigController {
    @Autowired
    private ISystemConfigService systemConfigService;
    @Autowired
    private IOperationLogService operationLogService;

    @PutMapping("/update")
    @RequiresPermissions("system:config")
    @Operation(summary = "更新系统字段")
    public Response update(@RequestBody SystemConfig systemConfig){
       systemConfigService.updateConfig(systemConfig);
        return Response.success();
    }


    @GetMapping()
    @RequiresPermissions("system:config")
    @Operation(summary = "查询所有系统字段")
    public Response list(){
        SystemConfig systemConfig = systemConfigService.getOne(null);
        return Response.success(systemConfig);
    }



    @GetMapping("/log")
    @RequiresPermissions("system:config")
    @Operation(summary = "查询系统日志")
    public Response listLog(@ModelAttribute @Validated PageDTO pageDTO,@ModelAttribute LogSearchDTO logSearchDTO){
        PageVO<OperationLogVO> list = operationLogService.getList(pageDTO, logSearchDTO);
        return Response.success(list);
    }

    @DeleteMapping("/log")
    @RequiresPermissions("system:config")
    @Operation(summary = "删除系统日志")
    public Response delLog(@RequestParam Integer num) {
        operationLogService.removeLatest(num);
        return Response.success();
    }


}
